<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>查看接机</title>
    </head>
    <body>
        <div id="seach_jj_form">
        </div>
        <div id="jj_ordersgrid" class="x-form-item">
        </div>
        <script>
            Ext.onReady(function(){
                var confirmStatus = new Ext.form.ComboBox({
                    store: new Ext.data.Store({
                        reader: new Ext.data.ArrayReader({}, ['value']),
                        data: [['所有'], ['未确认'], ['已确认'], ['已取消']]
                    }),
                    name: 'confirm_status',
                    fieldLabel: '接机状态',
                    resiable: true,
                    typeAhead: true,
                    width: 70,
                    handleHeight: 100,
                    displayField: 'value',
                    valueField: 'value',
                    nameField: 'confirm_status',
                    selectOnFocus: true,
                    mode: 'local',
                    selectOnFocus: true,
                    triggerAction: 'all', //这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                    readOnly: true,
                    value: '所有'
                });
                var pnrField = new Ext.form.TextField({
                    fieldLabel: 'PNR',
                    name: 'pnr',
                    allowBlank: true,
                    anchor: '70%'
                });
                var jjDate = new Ext.form.DateField({
                    fieldLabel: '接机日期',
                    name: 'jjDate',
                    id: 'jj_date',
                    altFormats: 'Y-m-d',
                    format: 'Y-m-d', //格式化日期
                    //disabledDays: [0,6],	//不让选择周六，周日
                    //disabledDaysText: "周末要休息",
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: false,
                    blankText: "起始日期不允许为空",
                    //emptyText: '请选择...',
                    inputType: '2008-01-01',
                    vtype: 'daterange',
                    endDateField: 'jj_date_to',
                    //anchor: '70%',
                    width: 90,
                    value: today
                });
                var jjDateTo = new Ext.form.DateField({
                    fieldLabel: '到',
                    name: 'jjDateTo',
                    id: 'jj_date_to',
                    altFormats: 'Y-m-d',
                    format: 'Y-m-d', //格式化日期
                    //disabledDays: [0,6],	//不让选择周六，周日
                    //disabledDaysText: "周末要休息",
                    invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                    allowBlank: false,
                    blankText: "结束日期不允许为空",
                    //emptyText: '请选择...',
                    inputType: '2008-01-01',
                    vtype: 'daterange',
                    startDateField: 'jj_date',
                    //anchor: '70%',
                    width: 90,
                    value: today
                });
                
                var queryButton = new Ext.Button({
                    text: '查 询',
                    handler: function(){
                        if (formPanel.form.isValid()) {
                            orderDS.baseParams.pnr = pnrField.getValue();
                            orderDS.baseParams.jj_status = confirmStatus.getValue();
                            orderDS.baseParams.date = jjDate.getValue().format('Y-m-d');
                            orderDS.baseParams.date_to = jjDateTo.getValue().format('Y-m-d');
                            orderDS.reload();
                        }
                    }
                });
                
                var formPanel = new Ext.form.FormPanel({
                    //baseCls: 'x-plain',
                    labelWidth: 65,
                    width: '100%',
                    frame: true,
                    labelAlign: 'right',
                    items: [{
                        layout: 'column',
                        border: false,
                        items: [{
                            columnWidth: .18,
                            layout: 'form',
                            border: false,
                            items: [jjDate]
                        }, {
                            columnWidth: .15,
                            labelWidth: 25,
                            layout: 'form',
                            border: false,
                            items: [jjDateTo]
                        }, {
                            columnWidth: .15,
                            layout: 'form',
                            border: false,
                            items: [confirmStatus]
                        }, {
                            columnWidth: .18,
                            labelWidth: 45,
                            layout: 'form',
                            border: false,
                            items: [pnrField]
                        }, {
                            columnWidth: .3,
                            layout: 'form',
                            border: false,
                            items: [queryButton]
                        }]
                    }]
                });
                
                formPanel.render('seach_jj_form');
                
                //############## 订单Grid ##############
                var ordercm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                    header: '编号',
                    dataIndex: 'id',
                    hidden: true
                }, {
                    header: '乘客人数',
                    dataIndex: 'seat',
                    sortable: true,
                    width: 60
                }, {
                    header: '接机日期',
                    dataIndex: 'fly_date',
                    sortable: true,
                    width: 70
                }, {
                    header: '接机时间',
                    dataIndex: 'jj_time',
                    sortable: true,
                    width: 60
                }, {
                    header: '起飞时间',
                    dataIndex: 'fly_time',
                    sortable: true,
                    width: 60
                }, {
                    header: '接机地址',
                    dataIndex: 'jj_address',
                    sortable: true,
                    width: 200
                }, {
                    header: '接机要求',
                    dataIndex: 'jj_request',
                    width: 120
                }, {
                    header: '总金额',
                    dataIndex: 'price_sum',
                    sortable: true,
                    width: 60
                }, {
                    header: '联系人',
                    dataIndex: 'link_man',
                    sortable: true,
                    width: 70
                }, {
                    header: '联系电话',
                    dataIndex: 'link_tel',
                    width: 100
                }, {
                    header: '接机人',
                    dataIndex: 'jj_man',
                    sortable: true,
                    width: 60
                }, {
                    header: '接机确认人',
                    dataIndex: 'jj_affirmer',
                    sortable: true,
                    width: 60
                }, {
                    header: '接机确认时间',
                    dataIndex: 'jj_affirm_date',
                    sortable: true,
                    width: 120,
                    renderer: Ext.util.Format.dateRenderer('Y-m-d h:m')
                }, {
                    header: '订单编号',
                    dataIndex: 'orderNo',
                    sortable: true,
                    width: 120
                }, {
                    header: 'PNR',
                    dataIndex: 'pnr',
                    width: 50
                }, {
                    header: '客户名称',
                    dataIndex: 'customer',
                    sortable: true,
                    width: 60
                }, {
                    header: '订单状态',
                    dataIndex: 'status',
                    sortable: true,
                    width: 60
                }, {
                    header: '预定员',
                    dataIndex: 'creator',
                    sortable: true,
                    width: 60
                }, {
                    header: '预定时间',
                    dataIndex: 'created_at',
                    sortable: true,
                    width: 120,
                    renderer: Ext.util.Format.dateRenderer('Y-m-d h:m')
                }, {
                    header: '客户要求',
                    dataIndex: 'order_request',
                    width: 120
                
                }]);
                
                var orderDS = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/orders/getJJList'
                    }),
                    reader: orderReader
                });
                
                var ordergridpanel = new Ext.grid.GridPanel({
                    el: 'jj_ordersgrid',
                    ds: orderDS,
                    cm: ordercm,
                    loadMask: true,
                    autoWidth: true,
                    collapsible: true,
                    animCollapse: true,
                    height: 500,
                    //frame: true,
                    title: '接机信息',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 16,
                        store: orderDS,
                        displayInfo: true,
                        displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
                        emptyMsg: "没有记录"
                    })
                
                });
                
                ordergridpanel.render();
                orderDS.load({
                    params: {
                        start: 0,
                        limit: 16
                    }
                });
                
                var ordersrow;
                var current_order_id;
                //订单右键菜单
                ordergridpanel.on('rowcontextmenu', function(customergridpanel, rowIndex, e){
                    var current_order_selected = orderDS.data.items[rowIndex].id;
                    ordersrow = orderDS.getById(current_order_selected);//ds为绑定到grid的数据源 
                    current_order_id = ordersrow.get("id");
                    e.preventDefault();
                    rightClick.showAt(e.getXY());
                });
                
                //############ 右键菜单 ##########
                var rightClick = new Ext.menu.Menu({
                    items: [{
                        handler: rightMenu1Fn,
                        text: '【取消接机】'
                    }, {
                        handler: rightMenu2Fn,
                        text: '【修改接机】'
                    }]
                });
                function rightMenu1Fn(){
					var jj_request = ordersrow.get("jj_request");
                    if (jj_request.indexOf("已取消") >= 0) {
					    Ext.MessageBox.alert('提示信息', '该条记录已被取消');
					}
					else {
						cancelJJ(current_order_id, orderDS);
					}
                }
				function rightMenu2Fn(){
					var jj_request = ordersrow.get("jj_request");
                    if (jj_request.indexOf("已取消") >= 0) {
					    Ext.MessageBox.alert('提示信息', '该条记录已被取消');
					}
					else {
						modJJ();
					}
				}
                function modJJ(){
                    var jj_address = new Ext.form.TextField({
                        fieldLabel: '接机地址',
                        name: 'jj_address',
                        allowBlank: false,
                        //emptyText: DEFAULT_JJ_ADDRESS,
                        anchor: '90%'
                    });
                    var jj_time = new Ext.form.TimeField({
                        fieldLabel: '接机时间',
                        name: 'jj_time',
                        altFormats: 'H:i',
                        format: 'H:i',
                        increment: 30,
                        allowBlank: false,
                        minValue: '06:00',
                        maxValue: '22:00',
                        //anchor: '50%'
                        width: 90
                    });
                    var jj_request = new Ext.form.TextField({
                        fieldLabel: '接机要求',
                        name: 'jj_request',
                        allowBlank: true,
                        anchor: '90%'
                    });
                    var jj_man = new Ext.form.ComboBox({
                        store: new Ext.data.Store({
                            proxy: new Ext.data.HttpProxy({
                                url: '/users/getAllUsersComboBox'
                            }),
                            reader: new Ext.data.JsonReader({
                                root: 'root'
                            }, ['id', 'user_name'])
                        }),
                        fieldLabel: '接机人',
                        name: 'jj_man_id',
                        loadingText: '正在加载...',
                        displayField: 'user_name',
                        valueField: 'id',
                        mode: 'remote',
                        //hideTrigger: true,
                        triggerAction: 'all',
                        hiddenName: 'jj_man_id',//如果不想提交displayField，则在这儿指定以提交ID的值．
                        //hiddenId:'sender',
                        emptyText: '请选择...',
                        editable: false,
                        allowBlank: false,
                        //forceSelection: false,
                        width: 90,
                        //maxHeight: 150,
                        tabIndex: 2
                    });
                    var formPanel = new Ext.form.FormPanel({
                        //baseCls: 'x-plain',
                        labelWidth: 60,
                        labelAlign: 'right',
                        frame: true,
                        url: "/orders/saveEditOrder?id=" + current_order_id + "&onlyJJ=yes",
                        reader: new Ext.data.JsonReader({
                            root: 'root'
                        }, ['jj_address', 'jj_time', 'jj_request', {
                            name: 'jj_man_id',
                            mapping: 'jj_man.user_name'
                        }]),
                        items: [jj_man, jj_time, jj_address, jj_request]
                    });
                    formPanel.form.load({
                        url: '/orders/getEditOrderInfoByID?id=' + current_order_id,
                        waitMsg: '正在载入数据...',
                        success: function(form, action){
                            //Ext.MessageBox.alert('提示信息', '信息加载成功！');
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提示信息', '信息加载失败');
                        }
                    });
                    //窗口
                    var modJJWindow = new Ext.Window({
                        title: '修改接机',
                        width: 390,
                        height: 210,
                        layout: 'fit',
                        plain: true,
                        bodyStyle: 'padding:5px;',
                        buttonAlign: 'center',
                        items: formPanel,
                        buttons: [{
                            text: '保存',
                            handler: function(){
                                if (formPanel.form.isValid()) {
                                    formPanel.form.submit({
                                        waitMsg: 'In processing',
                                        success: function(form, action){
                                            modJJWindow.hide();
                                            Ext.MessageBox.alert('操作信息', '修改接机信息成功');
                                            orderDS.reload();
                                        },
                                        failure: function(form, action){
                                            Ext.MessageBox.alert('操作信息', '修改接机信息失败');
                                        }
                                    });
                                }
                            }
                        }, {
                            text: '取消',
                            handler: function(){
                                modJJWindow.hide();
                            }
                        }]
                    });
                    modJJWindow.show();
                }
                
            })
        </script>
    </body>
</html>�